
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>分支预测器 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="6中断异常.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">前言</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">BoomV3</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../../BoomCode/chipyard-install.html">
            
                <a href="../../BoomCode/chipyard-install.html">
            
                    
                    Chipyard 1.8.0安装教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../../BoomCode/boom-debug.html">
            
                <a href="../../BoomCode/boom-debug.html">
            
                    
                    Boom调试【更新中】
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">论文阅读</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../../paper_read/prefetch-guard.html">
            
                <a href="../../paper_read/prefetch-guard.html">
            
                    
                    Prefetch-guard
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Gem5 学习</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../../gem5/gem5_fs.html">
            
                <a href="../../gem5/gem5_fs.html">
            
                    
                    X86 全系统模式模拟
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../../gem5/custom_disk_img.html">
            
                <a href="../../gem5/custom_disk_img.html">
            
                    
                    自定义磁盘镜像
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">一生一芯FangCore实现</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="1单周期CPU.html">
            
                <a href="1单周期CPU.html">
            
                    
                    单周期CPU实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="2五级流水.html">
            
                <a href="2五级流水.html">
            
                    
                    顺序五级流水CPU设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="3乘除法器.html">
            
                <a href="3乘除法器.html">
            
                    
                    乘除法功能单元
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="4AXI4总线.html">
            
                <a href="4AXI4总线.html">
            
                    
                    AXI4总线
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="5高速缓存Cache.html">
            
                <a href="5高速缓存Cache.html">
            
                    
                    高速缓存Cache设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="6中断异常.html">
            
                <a href="6中断异常.html">
            
                    
                    简单的中断异常支持
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="5.7" data-path="7分支预测器.html">
            
                <a href="7分支预测器.html">
            
                    
                    分支预测器
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >分支预测器</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x5206;&#x652F;&#x9884;&#x6D4B;&#x5668;">&#x5206;&#x652F;&#x9884;&#x6D4B;&#x5668;</h1>
<h2 id="&#x4E00;&#x3001;&#x6982;&#x8FF0;">&#x4E00;&#x3001;&#x6982;&#x8FF0;</h2>
<p>&#x6D41;&#x6C34;&#x7EBF;&#x6280;&#x672F;&#x5E26;&#x6765;&#x4E86;&#x63A7;&#x5236;&#x5192;&#x9669;&#x3002;&#x63A7;&#x5236;&#x5192;&#x9669;&#xFF0C;&#x4E5F;&#x79F0;&#x5206;&#x652F;&#x5192;&#x9669;&#x3002;&#x5728;&#x53D6;&#x51FA;&#x5206;&#x652F;&#x6307;&#x4EE4;&#x540E;&#xFF0C;&#x7D27;&#x8DDF;&#x7740;&#x4E0B;&#x4E00;&#x4E2A;&#x5468;&#x671F;&#x5C31;&#x4F1A;&#x53D6;&#x4E0B;&#x4E00;&#x6761;&#x6307;&#x4EE4;&#x3002;&#x4F46;&#x662F;&#x6D41;&#x6C34;&#x7EBF;&#x5E76;&#x4E0D;&#x77E5;&#x9053;&#x4E0B;&#x4E00;&#x6761;&#x6307;&#x4EE4;&#x5E94;&#x8BE5;&#x662F;&#x4EC0;&#x4E48;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x521A;&#x521A;&#x4ECE;&#x5B58;&#x50A8;&#x5668;&#x4E2D;&#x53D6;&#x51FA;&#x5206;&#x652F;&#x6307;&#x4EE4;&#xFF08;&#x5728;&#x6267;&#x884C;&#x7EA7;&#x624D;&#x80FD;&#x83B7;&#x5F97;&#x6B63;&#x786E;&#x7684;&#x4E0B;&#x4E00;&#x6761;&#x6307;&#x4EE4;&#x7684;&#x5730;&#x5740;&#xFF09;&#x3002;&#x4E00;&#x79CD;&#x89E3;&#x51B3;&#x529E;&#x6CD5;&#x662F;&#xFF0C;&#x5C06;&#x6D41;&#x6C34;&#x7EBF;&#x505C;&#x987F;&#xFF0C;&#x76F4;&#x5230;&#x5206;&#x652F;&#x6307;&#x4EE4;&#x7684;&#x7ED3;&#x679C;&#x88AB;&#x786E;&#x5B9A;&#x624D;&#x7EE7;&#x7EED;&#x8FDB;&#x884C;&#x53D6;&#x6307;&#x3002;&#x8FD9;&#x79CD;&#x4FDD;&#x5B88;&#x7684;&#x65B9;&#x6CD5;&#x662F;&#x884C;&#x4E4B;&#x6709;&#x6548;&#x7684;&#xFF0C;&#x4F46;&#x662F;&#x4F1A;&#x975E;&#x5E38;&#x8017;&#x65F6;&#xFF0C;&#x4E25;&#x91CD;&#x5F71;&#x54CD;&#x5904;&#x7406;&#x5668;&#x7684;&#x6027;&#x80FD;&#x3002;</p>
<ul>
<li>CPU&#x6BCF;&#x5468;&#x671F;&#x90FD;&#x4F1A;&#x4ECE;ICache&#x4E2D;&#x8FDB;&#x884C;&#x53D6;&#x6307;</li>
<li>&#x5F53;&#x9047;&#x5230;&#x5206;&#x652F;&#x6307;&#x4EE4;&#x65F6;&#xFF0C;CPU&#x65E0;&#x6CD5;&#x7ACB;&#x523B;&#x5F97;&#x5230;&#x4E0B;&#x4E00;&#x6761;&#x6307;&#x4EE4;&#x7684;&#x5730;&#x5740;&#x3002;&#x9700;&#x8981;&#x7B49;&#x5230;&#x6267;&#x884C;&#x7EA7;&#x624D;&#x80FD;&#x51B3;&#x5B9A;&#x5206;&#x652F;&#x662F;&#x5426;&#x53D1;&#x751F;</li>
<li>&#x4E3A;&#x4E86;&#x6B63;&#x786E;&#x6267;&#x884C;&#x6307;&#x4EE4;&#x6240;&#x4EA7;&#x751F;&#x7684;&#x5EF6;&#x8FDF;&#x79F0;&#x4E3A;&#x63A7;&#x5236;&#x5192;&#x9669;&#x6216;&#x5206;&#x652F;&#x5192;&#x9669;</li>
</ul>
<p><img src="https://cdn.jsdelivr.net/gh/fangjiangff/images/img/202208232132878.png" alt="image-20220823213236709" style="zoom: 67%;"></p>
<h2 id="&#x4E8C;&#x3001;&#x89E3;&#x51B3;&#x63A7;&#x5236;&#x5192;&#x9669;&#x7684;&#x65B9;&#x6848;">&#x4E8C;&#x3001;&#x89E3;&#x51B3;&#x63A7;&#x5236;&#x5192;&#x9669;&#x7684;&#x65B9;&#x6848;</h2>
<h3 id="21&#x3001;&#x7F29;&#x77ED;&#x5206;&#x652F;&#x5EF6;&#x8FDF;">2.1&#x3001;&#x7F29;&#x77ED;&#x5206;&#x652F;&#x5EF6;&#x8FDF;</h3>
<p>&#x4E00;&#x79CD;&#x63D0;&#x5347;&#x5206;&#x652F;&#x6027;&#x80FD;&#x7684;&#x65B9;&#x6CD5;&#x662F;<strong>&#x51CF;&#x5C11;&#x53D1;&#x751F;&#x5206;&#x652F;&#x65F6;&#x7684;&#x4EE3;&#x4EF7;</strong>&#x3002;&#x5206;&#x652F;&#x7684;&#x7ED3;&#x679C;&#x786E;&#x5B9A;&#x5F97;&#x8D8A;&#x65E9;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x51B2;&#x5237;&#x66F4;&#x5C11;&#x7684;&#x6307;&#x4EE4;&#x3002;</p>
<ul>
<li>&#x5C06;&#x5206;&#x652F;&#x68C0;&#x6D4B;&#x6A21;&#x5757;&#x79FB;&#x52A8;&#x5230;&#x8BD1;&#x7801;&#x7EA7;</li>
<li>&#x5206;&#x652F;&#x53D1;&#x751F;&#x65F6;&#x7684;&#x4EE3;&#x4EF7;&#x51CF;&#x8F7B;&#x5230;&#x53EA;&#x6709;&#x4E00;&#x6761;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x5206;&#x652F;&#x53D1;&#x751F;&#x65F6;&#x6B63;&#x5728;&#x53D6;&#x7684;&#x90A3;&#x4E00;&#x6761;</li>
<li>&#x5206;&#x652F;&#x53D1;&#x751F;&#x65F6;&#xFF1A;&#x5C06;&#x53D6;&#x5230;&#x7684;&#x6307;&#x4EE4;&#x6362;&#x6210;&#x4E00;&#x6761;nop&#x6307;&#x4EE4;&#x5373;&#x53EF;</li>
<li>&#x5206;&#x652F;&#x53D1;&#x751F;&#x65F6;&#xFF0C;&#x53EA;&#x4F1A;&#x4EA7;&#x751F;&#x4E00;&#x4E2A;&#x6D41;&#x6C34;&#x7EBF;&#x6C14;&#x6CE1;</li>
</ul>
<p>&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x5C06;&#x5206;&#x652F;&#x68C0;&#x6D4B;&#x6A21;&#x5757;&#x79FB;&#x52A8;&#x5230;ID&#x7EA7;&#xFF0C;==&#x9700;&#x8981;&#x989D;&#x5916;&#x7684;&#x5192;&#x9669;&#x68C0;&#x6D4B;&#x548C;&#x524D;&#x9012;==&#xFF0C;&#x56E0;&#x4E3A;&#x5206;&#x652F;&#x7ED3;&#x679C;&#x7684;&#x5224;&#x65AD;&#x53EF;&#x80FD;&#x4F9D;&#x8D56;&#x4E8E;&#x6D41;&#x6C34;&#x7EBF;&#x4E2D;&#x7684;&#x7ED3;&#x679C;&#x3002;</p>
<h3 id="22&#x3001;&#x9759;&#x6001;&#x5206;&#x652F;&#x9884;&#x6D4B;">2.2&#x3001;&#x9759;&#x6001;&#x5206;&#x652F;&#x9884;&#x6D4B;</h3>
<ul>
<li>&#x5047;&#x8BBE;&#x5206;&#x652F;&#x6C38;&#x8FDC;&#x4E0D;&#x53D1;&#x751F;&#xFF0C;&#x7A0B;&#x5E8F;&#x987A;&#x5E8F;&#x6267;&#x884C;</li>
<li>&#x8BD1;&#x7801;&#x7EA7;&#x8BA1;&#x7B97;&#x6B63;&#x786E;&#x7684;&#x5206;&#x652F;&#x7ED3;&#x679C;</li>
<li>&#x5982;&#x679C;&#x5206;&#x652F;&#x53D1;&#x751F;&#xFF0C;&#x5219;&#x91CD;&#x65B0;&#x8FDB;&#x884C;&#x53D6;&#x6307;&#xFF08;&#x4E0D;&#x6D89;&#x53CA;&#x6D41;&#x6C34;&#x7EBF;&#x51B2;&#x5237;&#xFF0C;&#x5982;&#x679C;&#x653E;&#x5728;&#x6267;&#x884C;&#x7EA7;&#x5F97;&#x51FA;&#x7ED3;&#x679C;&#xFF0C;&#x5219;&#x9700;&#x8981;&#xFF09;</li>
</ul>
<blockquote>
<p>&#x5206;&#x652F;&#x9884;&#x6D4B;&#xFF1A;&#x9884;&#x6D4B;&#x5206;&#x652F;&#x7684;&#x7ED3;&#x679C;&#x5E76;&#x6CBF;&#x9884;&#x6D4B;&#x7684;&#x65B9;&#x5411;&#x6267;&#x884C;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x7B49;&#x5F85;&#x5206;&#x652F;&#x7ED3;&#x679C;&#x786E;&#x5B9A;&#x540E;&#x624D;&#x5F00;&#x59CB;&#x6267;&#x884C;</p>
</blockquote>
<p>&#x8FD9;&#x4E5F;&#x662F;&#x4E66;&#x672C;&#x4E0A;&#x6240;&#x8BF4;&#x7684;<strong>&#x9759;&#x6001;&#x5206;&#x652F;&#x9884;&#x6D4B;&#x5668;</strong>&#x7684;&#x4E00;&#x79CD;&#x3002;&#x9759;&#x6001;&#x5206;&#x652F;&#x9884;&#x6D4B;&#x7684;&#x5E73;&#x5747;&#x6B63;&#x786E;&#x7387;&#x53EA;&#x6709;50%&#x3002;</p>
<h3 id="23-&#x52A8;&#x6001;&#x5206;&#x652F;&#x9884;&#x6D4B;">2.3 &#x52A8;&#x6001;&#x5206;&#x652F;&#x9884;&#x6D4B;</h3>
<p>&#x66F4;&#x6210;&#x719F;&#x7684;&#x5206;&#x652F;&#x9884;&#x6D4B;&#x662F;&#x9884;&#x6D4B;&#x4E00;&#x4E9B;&#x5206;&#x652F;&#x6307;&#x4EE4;&#x53D1;&#x751F;&#xFF0C;&#x800C;&#x53E6;&#x4E00;&#x4E9B;&#x4E0D;&#x53D1;&#x751F;&#x3002;&#x5177;&#x4F53;&#x6765;&#x8BF4;&#xFF0C;&#x4FDD;&#x5B58;&#x6BCF;&#x4E2A;&#x6761;&#x4EF6;&#x5206;&#x652F;&#x7684;&#x5386;&#x53F2;&#x8BB0;&#x5F55;&#xFF0C;==&#x6839;&#x636E;&#x8FC7;&#x53BB;&#x7684;&#x884C;&#x4E3A;&#x6765;&#x9884;&#x6D4B;&#x672A;&#x6765;==&#x3002;</p>
<h4 id="231-bht-&#x5206;&#x652F;&#x5386;&#x53F2;&#x8868;">2.3.1 BHT &#x5206;&#x652F;&#x5386;&#x53F2;&#x8868;</h4>
<p>&#x5206;&#x652F;&#x5386;&#x53F2;&#x8868;&#xFF0C;&#x5373;BHT (branch target table)&#xFF0C;&#x987E;&#x540D;&#x601D;&#x4E49;&#xFF0C;&#x662F;&#x7528;&#x6765;<strong>&#x8BB0;&#x5F55;&#x5206;&#x652F;&#x8DF3;&#x8F6C;&#x5386;&#x53F2;&#x6267;&#x884C;&#x6A21;&#x5F0F;&#x7684;&#x7ED3;&#x6784;&#x5355;&#x5143;</strong>&#x3002;</p>
<h4 id="232-pht-&#x6A21;&#x5F0F;&#x5386;&#x53F2;&#x8868;">2.3.2 PHT &#x6A21;&#x5F0F;&#x5386;&#x53F2;&#x8868;</h4>
<p>PHT&#x8BB0;&#x5F55;&#x4E0D;&#x540C;&#x5206;&#x652F;&#x5386;&#x53F2;&#x6267;&#x884C;&#x6A21;&#x5F0F;&#x7684;<strong>&#x9884;&#x6D4B;&#x8DF3;&#x8F6C;&#x72B6;&#x6001;</strong>&#x3002;&#x4F7F;&#x7528;2bit&#x8FDB;&#x884C;&#x8BB0;&#x5F55;&#x3002;00 &#x5F3A;&#x4E0D;&#x8DF3;&#x8F6C;&#x3001;01 &#x5F31;&#x4E0D;&#x8DF3;&#x8F6C;&#x3001;10&#x5F31;&#x8DF3;&#x8F6C;&#x3001;11&#x5F3A;&#x8DF3;&#x8F6C;&#x3002;&#x8BFB;&#x51FA;PHT&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x4E24;&#x4F4D;&#x9884;&#x6D4B;&#x72B6;&#x6001;&#x4F4D;&#xFF0C;&#x53D6;&#x4E24;&#x4F4D;&#x9884;&#x6D4B;&#x72B6;&#x6001;&#x4F4D;&#x7684;<strong>&#x6700;&#x9AD8;&#x4F4D;</strong>&#x4F5C;&#x4E3A;&#x9884;&#x6D4B;&#x7ED3;&#x679C;&#xFF0C;&#x4E3A;1&#x4E3A;&#x9884;&#x6D4B;&#x8DF3;&#x8F6C;&#xFF0C;&#x4E3A;0&#x4E3A;&#x9884;&#x6D4B;&#x4E0D;&#x8DF3;&#x3002;</p>
<ul>
<li>PHT&#x7684;&#x8868;&#x9879;&#x7A7A;&#x95F4;&#x662F;&#x6240;&#x6709;&#x5206;&#x652F;&#x6307;&#x4EE4;&#x5171;&#x4EAB;</li>
<li>&#x5177;&#x6709;&#x76F8;&#x540C;&#x5386;&#x53F2;&#x6267;&#x884C;&#x6A21;&#x5F0F;&#x7684;&#x5206;&#x652F;&#x4F1A;&#x7D22;&#x5F15;&#x5230;PHT&#x4E2D;&#x7684;&#x540C;&#x4E00;&#x4E2A;&#x8868;&#x9879;</li>
<li>&#x4E3A;&#x4E86;&#x907F;&#x514D;&#x4E0D;&#x540C;&#x5206;&#x652F;&#x6307;&#x4EE4;&#x4E4B;&#x95F4;&#x7684;&#x4E92;&#x76F8;&#x5E72;&#x6270;&#xFF0C;&#x5728;&#x67E5;PHT&#x8868;&#x524D;&#xFF0C;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x5206;&#x652F;&#x6307;&#x4EE4;&#x4E0E;BHT&#x7684;&#x503C;&#x8FDB;&#x884C;&#x5F02;&#x6216;&#x8FD0;&#x7B97;&#xFF0C;&#x4ECE;&#x800C;&#x5C06;&#x5177;&#x6709;&#x76F8;&#x540C;&#x6267;&#x884C;&#x6A21;&#x5F0F;&#x7684;&#x5206;&#x652F;&#x6620;&#x5C04;&#x5230;PHT&#x4E2D;&#x7684;&#x4E0D;&#x540C;&#x8868;&#x9879;&#x4F4D;&#x7F6E;</li>
</ul>
<h4 id="233-btb-&#x5206;&#x652F;&#x76EE;&#x6807;&#x7F13;&#x51B2;&#x533A;">2.3.3 BTB &#x5206;&#x652F;&#x76EE;&#x6807;&#x7F13;&#x51B2;&#x533A;</h4>
<p>&#x5206;&#x652F;&#x76EE;&#x6807;&#x7F13;&#x51B2;&#x5668;&#xFF0C;&#x5373;BTB(branch target table)&#xFF0C;&#x4F1A;&#x5C06;&#x5206;&#x652F;&#x6307;&#x4EE4;&#x6807;&#x5FD7; (tag)&#x4EE5;&#x53CA;&#x5176;&#x5BF9;&#x5E94;&#x7684;&#x8DF3;&#x8F6C;&#x76EE;&#x6807; (target)&#x7F13;&#x5B58;&#x5728;<strong>&#x7F13;&#x51B2;&#x533A;</strong>&#x4E2D;&#xFF0C;&#x53EF;&#x4EE5;&#x662F;&#x7EDD;&#x5BF9;&#x8DF3;&#x8F6C;&#x6307;&#x4EE4;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x6761;&#x4EF6;&#x8DF3;&#x8F6C;&#x6307;&#x4EE4;&#xFF0C;&#x5F53;&#x6307;&#x4EE4;PC<strong>&#x547D;&#x4E2D;</strong>&#x7F13;&#x51B2;&#x533A;&#x4E2D;&#x7684;&#x67D0;&#x4E00;&#x9879;&#x65F6;&#xFF0C;&#x4F1A;&#x5C06;&#x4ECE;<strong>BTB</strong>&#x4E2D;&#x8BFB;&#x51FA;&#x7684;&#x8DF3;&#x8F6C;&#x76EE;&#x6807;&#xFF0C;&#x5C06;&#x5176;&#x4F5C;&#x4E3A;&#x4E0B;&#x4E00;&#x6B21;&#x53D6;&#x6307;&#x7684;PC&#x3002;</p>
<h2 id="&#x4E09;&#x3001;&#x52A8;&#x6001;&#x5206;&#x652F;&#x9884;&#x6D4B;&#x5B9E;&#x73B0;">&#x4E09;&#x3001;&#x52A8;&#x6001;&#x5206;&#x652F;&#x9884;&#x6D4B;&#x5B9E;&#x73B0;</h2>
<p>&#x5206;&#x652F;&#x9884;&#x6D4B;&#x5668;&#x9700;&#x8981;&#x89E3;&#x51B3;&#x4E24;&#x4E2A;&#x95EE;&#x9898;&#xFF1A;</p>
<ul>
<li>&#x8BE5;&#x5206;&#x652F;&#x6307;&#x4EE4;&#x662F;&#x5426;&#x8DF3;&#x8F6C;&#xFF1F;&#xFF08;taken&#xFF1F;&#xFF09;</li>
<li>&#x5982;&#x679C;&#x8DF3;&#x8F6C;&#xFF0C;&#x8DF3;&#x8F6C;&#x7684;&#x76EE;&#x6807;&#x5730;&#x5740;&#x662F;&#x54EA;&#x91CC;&#xFF08;target&#xFF1F;&#xFF09;</li>
</ul>
<p>&#x672C;&#x6B21;ysyx&#x4E2D;&#xFF0C;&#x91C7;&#x7528;&#x5206;&#x652F;&#x5386;&#x53F2;&#x8868;BHT&#x4E0E;&#x6A21;&#x5F0F;&#x5386;&#x53F2;&#x8868;PHT&#x5224;&#x65AD;&#x5206;&#x652F;&#x662F;&#x5426;&#x53D1;&#x751F;&#x3002;&#x4F7F;&#x7528;BTB&#x6765;&#x83B7;&#x5F97;&#x5206;&#x652F;&#x8DF3;&#x8F6C;&#x7684;&#x5730;&#x5740;&#x3002;</p>
<p><img src="https://cdn.jsdelivr.net/gh/fangjiangff/images/img/202208241029163.png" alt="image-20220824102920088" style="zoom:50%;"></p>
<h4 id="&#x2460;-&#x5206;&#x652F;&#x9884;&#x6D4B;&#x5355;&#x5143;&#x7684;&#x9876;&#x5C42;&#x63A5;&#x53E3;">&#x2460; &#x5206;&#x652F;&#x9884;&#x6D4B;&#x5355;&#x5143;&#x7684;&#x9876;&#x5C42;&#x63A5;&#x53E3;</h4>
<ul>
<li>&#x53D6;&#x6307;&#x9636;&#x6BB5;&#xFF0C;&#x6839;&#x636E;PC&#x503C;&#xFF0C;&#x8BBF;&#x95EE;&#x5206;&#x652F;&#x9884;&#x6D4B;&#x5355;&#x5143;&#xFF0C;&#x83B7;&#x53D6;&#x9884;&#x6D4B;&#x7ED3;&#x679C;&#x3002;&#x6839;&#x636E;&#x9884;&#x6D4B;&#x7684;&#x7ED3;&#x679C;&#x8FDB;&#x884C;&#x4E0B;&#x4E00;&#x6761;&#x6307;&#x4EE4;&#x7684;&#x53D6;&#x6307;</li>
<li>&#x8BD1;&#x7801;&#x9636;&#x6BB5;&#xFF0C;&#x83B7;&#x53D6;&#x6B63;&#x786E;&#x7684;&#x5206;&#x652F;&#x8DF3;&#x8F6C;&#x7ED3;&#x679C;&#x3002;&#x66F4;&#x65B0;&#x5206;&#x652F;&#x9884;&#x6D4B;&#x6A21;&#x5757;</li>
</ul>
<p>&#x56E0;&#x6B64;&#xFF0C;&#x5206;&#x652F;&#x9884;&#x6D4B;&#x5355;&#x5143;&#x7684;&#x9876;&#x5C42;&#x63A5;&#x53E3;&#xFF0C;&#x8BBE;&#x8BA1;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-scala"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">JmpIO</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Bundle</span></span>{
    <span class="hljs-keyword">val</span> valid       = <span class="hljs-type">Input</span>(<span class="hljs-type">Bool</span>())         <span class="hljs-comment">//&#x5305;&#x5185;&#x4FE1;&#x53F7;&#x662F;&#x5426;&#x6709;&#x6548;</span>
    <span class="hljs-keyword">val</span> id_pc       = <span class="hljs-type">Input</span>(<span class="hljs-type">UInt</span>(<span class="hljs-number">32.</span><span class="hljs-type">W</span>))     <span class="hljs-comment">//&#x6307;&#x4EE4;&#x7684;pc&#x503C;</span>
    <span class="hljs-keyword">val</span> id_taken    = <span class="hljs-type">Input</span>(<span class="hljs-type">Bool</span>())         <span class="hljs-comment">//id&#x9636;&#x6BB5;&#xFF0C;&#x662F;&#x5426;&#x8DF3;&#x8F6C;</span>
    <span class="hljs-keyword">val</span> id_target   = <span class="hljs-type">Input</span>(<span class="hljs-type">UInt</span>(<span class="hljs-number">32.</span><span class="hljs-type">W</span>))     <span class="hljs-comment">//id&#x9636;&#x6BB5;&#xFF0C;&#x8DF3;&#x8F6C;&#x7684;&#x5730;&#x5740;</span>
    <span class="hljs-keyword">val</span> pred_mis    = <span class="hljs-type">Input</span>(<span class="hljs-type">Bool</span>())         <span class="hljs-comment">//&#x662F;&#x5426;&#x9884;&#x6D4B;&#x9519;&#x8BEF;</span>
}
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">BranchPredictor</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Module</span> <span class="hljs-keyword">with</span> <span class="hljs-title">BranchPredParas</span></span>{
    <span class="hljs-keyword">val</span> io = <span class="hljs-type">IO</span>(<span class="hljs-keyword">new</span> <span class="hljs-type">Bundle</span>{
        <span class="hljs-keyword">val</span> if_pc       = <span class="hljs-type">Input</span>(<span class="hljs-type">UInt</span>(<span class="hljs-number">32.</span><span class="hljs-type">W</span>))
        <span class="hljs-keyword">val</span> if_inst     = <span class="hljs-type">Input</span>(<span class="hljs-type">UInt</span>(<span class="hljs-number">32.</span><span class="hljs-type">W</span>))
        <span class="hljs-comment">// val is_branch   = Input(Bool())   //&#x662F;&#x5426;&#x662F;&#x5206;&#x652F;&#x6307;&#x4EE4;</span>

        <span class="hljs-keyword">val</span> redirect    = <span class="hljs-keyword">new</span> <span class="hljs-type">JmpIO</span>

        <span class="hljs-keyword">val</span> taken   = <span class="hljs-type">Output</span>(<span class="hljs-type">Bool</span>())         <span class="hljs-comment">//&#x9884;&#x6D4B;&#x8DF3;&#x8F6C;&#x7684;&#x65B9;&#x5411;</span>
        <span class="hljs-keyword">val</span> target  = <span class="hljs-type">Output</span>(<span class="hljs-type">UInt</span>(<span class="hljs-number">32.</span><span class="hljs-type">W</span>))        <span class="hljs-comment">//&#x9884;&#x6D4B;&#x8DF3;&#x8F6C;&#x7684;&#x5730;&#x5740;</span>
    })
}
</code></pre>
<h4 id="&#x2461;-&#x6A21;&#x5757;&#x53C2;&#x6570;&#x53CA;&#x5176;&#x521D;&#x59CB;&#x5316;">&#x2461; &#x6A21;&#x5757;&#x53C2;&#x6570;&#x53CA;&#x5176;&#x521D;&#x59CB;&#x5316;</h4>
<ul>
<li>BHT &#x6709;64&#x4E2A;&#x8868;&#x9879;&#xFF0C;&#x6BCF;&#x4E2A;&#x8868;&#x9879;&#x5927;&#x5C0F;&#x4E3A;6bit&#x3002;&#x5373;&#x53EF;&#x4EE5;&#x8BB0;&#x5F55;&#x8BE5;&#x5206;&#x652F;&#x7684;6&#x6B21;&#x5386;&#x53F2;&#x8DF3;&#x8F6C;&#x60C5;&#x51B5;</li>
<li>PHT &#x6709;512&#x4E2A;&#x8868;&#x9879;&#xFF0C;&#x5206;&#x4E3A;8&#x8DEF;&#xFF0C;&#x6BCF;&#x4E00;&#x8DEF;&#x6709;64&#x4E2A;&#x8868;&#x9879;&#x3002;</li>
<li>BTB &#x6709;64&#x4E2A;&#x8868;&#x9879;&#x3002;&#x6BCF;&#x4E2A;&#x8868;&#x9879;&#x7531;valid&#x3001;tag&#x548C;target&#x7EC4;&#x6210;</li>
</ul>
<pre><code class="lang-scala"><span class="hljs-class"><span class="hljs-keyword">trait</span> <span class="hljs-title">BranchPredParas</span> </span>{
    <span class="hljs-comment">//BHT  branch history table</span>
    <span class="hljs-keyword">val</span> <span class="hljs-type">BhtWidth</span>        = <span class="hljs-number">6</span>
    <span class="hljs-keyword">val</span> <span class="hljs-type">BhtLines</span>        = <span class="hljs-number">64</span> 
    <span class="hljs-keyword">val</span> <span class="hljs-type">BhtAddrBits</span>     = log2Up(<span class="hljs-type">BhtLines</span>)<span class="hljs-comment">//6   </span>
    <span class="hljs-comment">//PHT Pattern Histroy Table</span>
    <span class="hljs-keyword">val</span> <span class="hljs-type">PhtLines</span>    = <span class="hljs-number">64</span>
    <span class="hljs-keyword">val</span> <span class="hljs-type">PhtWays</span>     = <span class="hljs-number">8</span> <span class="hljs-comment">//512&#x9879;       </span>
    <span class="hljs-keyword">val</span> <span class="hljs-type">PhtAddrBits</span> = log2Up(<span class="hljs-type">PhtLines</span>)<span class="hljs-comment">//8</span>
    <span class="hljs-comment">//BTB Branch Target Buffer</span>
    <span class="hljs-keyword">val</span> <span class="hljs-type">BtbLines</span>    = <span class="hljs-number">64</span>
    <span class="hljs-keyword">val</span> <span class="hljs-type">BtbAddrBits</span> = log2Up(<span class="hljs-type">BtbLines</span>) <span class="hljs-comment">//6</span>
    <span class="hljs-keyword">val</span> <span class="hljs-type">BtbTagBits</span>  = <span class="hljs-number">8</span> 
}
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">bimDefalut</span></span>(): <span class="hljs-type">UInt</span> = <span class="hljs-string">&quot;b01&quot;</span>.<span class="hljs-type">U</span>(<span class="hljs-number">2.</span><span class="hljs-type">W</span>)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">btbEntry</span></span>() = <span class="hljs-keyword">new</span> <span class="hljs-type">Bundle</span>{
    <span class="hljs-keyword">val</span> valid   = <span class="hljs-type">Bool</span>()
    <span class="hljs-keyword">val</span> tag     = <span class="hljs-type">UInt</span>(<span class="hljs-type">BtbTagBits</span>.<span class="hljs-type">W</span>) <span class="hljs-comment">//8 bits</span>
    <span class="hljs-keyword">val</span> target  = <span class="hljs-type">UInt</span>(<span class="hljs-number">32.</span><span class="hljs-type">W</span>)
}
<span class="hljs-keyword">val</span> <span class="hljs-type">BHT</span> = <span class="hljs-type">RegInit</span>(<span class="hljs-type">VecInit</span>(<span class="hljs-type">Seq</span>.fill(<span class="hljs-type">BhtLines</span>)(<span class="hljs-number">0.</span><span class="hljs-type">U</span>(<span class="hljs-type">BhtWidth</span>.<span class="hljs-type">W</span>)))) <span class="hljs-comment">//64*6</span>
<span class="hljs-keyword">val</span> <span class="hljs-type">PHT</span> = <span class="hljs-type">RegInit</span>(<span class="hljs-type">VecInit</span>(<span class="hljs-type">Seq</span>.fill(<span class="hljs-type">PhtWays</span>)(<span class="hljs-type">VecInit</span>(<span class="hljs-type">Seq</span>.fill(<span class="hljs-type">PhtLines</span>)(bimDefalut())))))<span class="hljs-comment">//8*64*2</span>
<span class="hljs-keyword">val</span> <span class="hljs-type">BTB</span> = <span class="hljs-type">RegInit</span>(<span class="hljs-type">VecInit</span>(<span class="hljs-type">Seq</span>.fill(<span class="hljs-type">BtbLines</span>)(<span class="hljs-number">0.</span><span class="hljs-type">U</span>.asTypeOf(btbEntry()))))
</code></pre>
<h3 id="31--&#x9884;&#x6D4B;&#x662F;&#x5426;&#x8DF3;&#x8F6C;">3.1  &#x9884;&#x6D4B;&#x662F;&#x5426;&#x8DF3;&#x8F6C;</h3>
<ol>
<li>&#x4F7F;&#x7528;PC&#x7684;2-7&#x4F4D;&#x4F5C;&#x4E3A;&#x7D22;&#x5F15;&#xFF0C;&#x83B7;&#x53D6;&#x5206;&#x652F;&#x7684;&#x5386;&#x53F2;&#x8DF3;&#x8F6C;&#x6A21;&#x5F0F;&#x3002;&#x5982;&#x7D22;&#x5F15;&#x4E3A;<strong>000_011</strong>&#xFF0C;&#x83B7;&#x53D6;BHT&#x8868;&#x9879;&#x5185;&#x5BB9;&#x4E3A;<strong>110_010</strong></li>
<li>&#x4F7F;&#x7528;PC&#x7684;2-7&#x4F4D;&#x4E0E;BTB&#x7684;&#x8868;&#x9879;&#x5185;&#x5BB9;&#x8FDB;&#x884C;&#x5F02;&#x6216;&#xFF0C;&#x5F97;&#x51FA;&#x7684;&#x7ED3;&#x679C;&#x4F5C;&#x4E3A;PHT&#x7684;&#x884C;&#x7D22;&#x5F15;&#x3002;&#x5982;000_011&#x2295;110_010 = 011_011</li>
<li>&#x4F7F;&#x7528;PC&#x7684;8-10&#x4F4D;&#x4F5C;&#x4E3A;PHT&#x7684;&#x8DEF;&#x7D22;&#x5F15;&#x3002;&#x5982;pc(10,8)&#x4E3A;000&#xFF0C;&#x5219;&#x7D22;&#x5F15;&#x5230;PHT&#x7684;0&#x8DEF;&#x4E2D;</li>
<li>&#x6839;&#x636E;2&#x3001;3&#x6B65;&#x9AA4;&#x83B7;&#x53D6;&#x7684;&#x8DEF;&#x6570;&#x548C;&#x884C;&#x6570;&#xFF0C;&#x5373;&#x53EF;&#x83B7;&#x53D6;&#x9884;&#x6D4B;&#x72B6;&#x6001;&#x503C;&#x3002;&#x5982;&quot;10&quot;&#xFF0C;&#x53D6;&#x9AD8;&#x4F4D;&#xFF0C;&#x5219;&#x7ED3;&#x679C;&#x4E3A;&#x8DF3;&#x8F6C;</li>
</ol>
<p><img src="https://cdn.jsdelivr.net/gh/fangjiangff/images/img/202208232241952.png" alt="image-20220823224129862" style="zoom:50%;"></p>
<p>&#x5177;&#x4F53;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-scala">    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">bhtIndex</span></span>(pc: <span class="hljs-type">UInt</span>)  : <span class="hljs-type">UInt</span> = pc(<span class="hljs-number">7</span>, <span class="hljs-number">2</span>)                <span class="hljs-comment">//pc(7,2)</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">phtIndex</span></span>(bht: <span class="hljs-type">UInt</span>, pc: <span class="hljs-type">UInt</span>): <span class="hljs-type">UInt</span> = bht ^ pc(<span class="hljs-number">7</span>, <span class="hljs-number">2</span>) <span class="hljs-comment">// bht ^ pc(9,2) 8&#x4F4D;</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">phtWay</span></span>(pc: <span class="hljs-type">UInt</span>)    : <span class="hljs-type">UInt</span> = pc(<span class="hljs-number">10</span>,<span class="hljs-number">8</span>)
    <span class="hljs-comment">//&#x8BFB;&#x7B56;&#x7565;</span>
    <span class="hljs-keyword">val</span> bht_ridx    = bhtIndex(if_pc) 
    <span class="hljs-keyword">val</span> bht         = <span class="hljs-type">BHT</span>(bht_ridx)
    <span class="hljs-keyword">val</span> pht_ridx    = phtIndex(bht, if_pc)
    <span class="hljs-keyword">val</span> pht_rway    = phtWay(if_pc)
    <span class="hljs-keyword">val</span> pht_taken   = <span class="hljs-type">PHT</span>(pht_rway)(pht_ridx)(<span class="hljs-number">1</span>).asBool() <span class="hljs-comment">//&#x6839;&#x636E;&#x9AD8;&#x4F4D;&#x5224;&#x65AD;&#x662F;&#x5426;&#x8DF3;&#x8F6C;</span>
</code></pre>
<h3 id="32-&#x9884;&#x6D4B;&#x8DF3;&#x8F6C;&#x7684;&#x5730;&#x5740;">3.2 &#x9884;&#x6D4B;&#x8DF3;&#x8F6C;&#x7684;&#x5730;&#x5740;</h3>
<ol>
<li>PC&#x7684;2-7&#x4F4D;&#x4F5C;&#x4E3A;BTB&#x7684;&#x7D22;&#x5F15;&#x3002;&#x5982;pc(7,2)&#x4E3A;000_011&#xFF0C;&#x7D22;&#x5F15;&#x5230;BTB&#x7684;&#x7B2C;3&#x884C;</li>
<li>PC&#x7684;8-15&#x4F4D;&#x4E0E;BTB&#x4E2D;&#x7684;tag&#x8FDB;&#x884C;&#x5BF9;&#x6BD4;&#x3002;&#x76F8;&#x540C;&#x4E14;valid&#x4E3A;&#x9AD8;&#x65F6;&#xFF0C;&#x8868;&#x793A;&#x547D;&#x4E2D;</li>
<li>&#x547D;&#x4E2D;BTB&#x8868;&#x9879;&#x65F6;&#xFF0C;&#x5C06;&#x8868;&#x9879;&#x4E2D;&#x8BB0;&#x5F55;&#x7684;targe_pc&#x4F5C;&#x4E3A;&#x5206;&#x652F;&#x8DF3;&#x8F6C;&#x7684;&#x76EE;&#x6807;&#x5730;&#x5740;</li>
</ol>
<p><img src="https://cdn.jsdelivr.net/gh/fangjiangff/images/img/202208241002180.png" alt="image-20220823230130276" style="zoom: 67%;"></p>
<p>&#x5177;&#x4F53;&#x4EE3;&#x7801;&#x5982;&#x4E0B;</p>
<pre><code class="lang-scala"><span class="hljs-keyword">val</span> btb_ridx    = btbIndex(if_pc)
<span class="hljs-keyword">val</span> btb         = <span class="hljs-type">BTB</span>(btb_ridx)
<span class="hljs-keyword">val</span> btb_hit     = is_branch &amp;&amp; btb.valid &amp;&amp; (btb.tag === btbTag(if_pc))
when(pht_taken){<span class="hljs-comment">//&#x5206;&#x652F;&#x8DF3;&#x8F6C;</span>
    pred_taken  := btb_hit
    pred_target := <span class="hljs-type">Mux</span>(btb_hit, btb.target, snpc)
}.otherwise{    <span class="hljs-comment">//&#x5206;&#x652F;&#x4E0D;&#x8DF3;&#x8F6C;</span>
    pred_taken  := <span class="hljs-literal">false</span>.<span class="hljs-type">B</span> 
    pred_target := snpc
}
</code></pre>
<h3 id="33&#x66F4;&#x65B0;&#x5206;&#x652F;&#x9884;&#x6D4B;&#x5668;">3.3&#x66F4;&#x65B0;&#x5206;&#x652F;&#x9884;&#x6D4B;&#x5668;</h3>
<h4 id="&#x2460;-&#x8BD1;&#x7801;&#x9636;&#x6BB5;&#x83B7;&#x53D6;&#x5206;&#x652F;&#x7ED3;&#x679C;">&#x2460; &#x8BD1;&#x7801;&#x9636;&#x6BB5;&#x83B7;&#x53D6;&#x5206;&#x652F;&#x7ED3;&#x679C;</h4>
<pre><code class="lang-scala"><span class="hljs-keyword">val</span> br_ctrl                = <span class="hljs-type">Module</span>(<span class="hljs-keyword">new</span> <span class="hljs-type">BrCtrl</span>())    <span class="hljs-comment">//&#x5206;&#x652F;&#x5224;&#x65AD;&#x5355;&#x5143;</span>
<span class="hljs-keyword">val</span> jmp_taken           = br_ctrl.io.taken || v_time_int  <span class="hljs-comment">//&#x8003;&#x8651;&#x4E86;&#x8BA1;&#x6570;&#x5668;&#x4E2D;&#x65AD;</span>
<span class="hljs-keyword">val</span> jmp_pc              =  <span class="hljs-type">Mux</span>(v_time_int, <span class="hljs-type">Cat</span>(io.mtvec(<span class="hljs-number">31</span>, <span class="hljs-number">2</span>), <span class="hljs-type">Fill</span>(<span class="hljs-number">2</span>, <span class="hljs-number">0.</span><span class="hljs-type">U</span>)), br_ctrl.io.target)
io.redirect.valid       := is_br || v_time_int <span class="hljs-comment">//&#x9700;&#x8981;&#x66F4;&#x65B0;&#x5206;&#x652F;&#x9884;&#x6D4B;&#x90E8;&#x5206;</span>
io.redirect.id_pc       := io.in.pc
io.redirect.id_taken    := jmp_taken            <span class="hljs-comment">//&#x53D1;&#x751F;&#x5206;&#x652F;&#x8DF3;&#x8F6C;</span>
io.redirect.id_target   := jmp_pc
io.redirect.pred_mis    := io.redirect.valid &amp;&amp; mis_predict
</code></pre>
<h4 id="&#x2461;-&#x66F4;&#x65B0;&#x5206;&#x652F;&#x9884;&#x6D4B;&#x5668;">&#x2461; &#x66F4;&#x65B0;&#x5206;&#x652F;&#x9884;&#x6D4B;&#x5668;</h4>
<ul>
<li>BHT&#x5206;&#x652F;&#x5386;&#x53F2;&#x8868;&#xFF0C;&#x8BB0;&#x5F55;&#x5206;&#x652F;&#x7684;&#x8DF3;&#x8F6C;&#x60C5;&#x51B5;&#xFF0C;&#x56E0;&#x6B64;&#x6BCF;&#x9047;&#x5230;&#x5206;&#x652F;&#x6307;&#x4EE4;&#x90FD;&#x9700;&#x8981;&#x8FDB;&#x884C;&#x66F4;&#x65B0;</li>
<li>PHT&#x540C;&#x7406;&#x3002;&#x9700;&#x8981;&#x66F4;&#x65B0;&#x9884;&#x6D4B;&#x72B6;&#x6001;&#x4F4D;&#x3002;&#xFF08;&#x72B6;&#x6001;&#x673A;&#x53C2;&#x8003;2bit&#x9971;&#x548C;&#x8BA1;&#x6570;&#x5668;&#xFF09;</li>
<li>BTB&#xFF0C;&#x8BB0;&#x5F55;&#x5206;&#x652F;&#x53D1;&#x751F;&#x65F6;&#xFF0C;&#x8DF3;&#x8F6C;&#x7684;&#x76EE;&#x6807;&#x5730;&#x5740;&#x3002;&#x56E0;&#x6B64;&#x5F53;&#x8BD1;&#x7801;&#x7EA7;&#x786E;&#x5B9A;&#x5206;&#x652F;&#x8DF3;&#x8F6C;&#x53D1;&#x751F;&#x65F6;&#xFF0C;&#x9700;&#x8981;&#x8FDB;&#x884C;&#x66F4;&#x65B0;&#x3002;</li>
</ul>
<p>&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-scala">when(redirect.valid){   <span class="hljs-comment">//&#x66F4;&#x65B0;BHT&#x548C;PHT</span>
    <span class="hljs-type">BHT</span>(bht_widx) := <span class="hljs-type">Cat</span>(redirect.id_taken.asUInt(), bht_wrdate(<span class="hljs-type">BhtWidth</span> - <span class="hljs-number">1</span>, <span class="hljs-number">1</span>))
    pht_state   := <span class="hljs-type">LookupTreeDefault</span>(pht_state, bimDefalut(), <span class="hljs-type">List</span>(
        <span class="hljs-string">&quot;b00&quot;</span>.<span class="hljs-type">U</span>(<span class="hljs-number">2.</span><span class="hljs-type">W</span>)    -&gt; <span class="hljs-type">Mux</span>(redirect.id_taken, <span class="hljs-string">&quot;b01&quot;</span>.<span class="hljs-type">U</span>(<span class="hljs-number">2.</span><span class="hljs-type">W</span>), <span class="hljs-string">&quot;b00&quot;</span>.<span class="hljs-type">U</span>(<span class="hljs-number">2.</span><span class="hljs-type">W</span>)),
        <span class="hljs-string">&quot;b01&quot;</span>.<span class="hljs-type">U</span>(<span class="hljs-number">2.</span><span class="hljs-type">W</span>)    -&gt; <span class="hljs-type">Mux</span>(redirect.id_taken, <span class="hljs-string">&quot;b10&quot;</span>.<span class="hljs-type">U</span>(<span class="hljs-number">2.</span><span class="hljs-type">W</span>), <span class="hljs-string">&quot;b00&quot;</span>.<span class="hljs-type">U</span>(<span class="hljs-number">2.</span><span class="hljs-type">W</span>)),
        <span class="hljs-string">&quot;b10&quot;</span>.<span class="hljs-type">U</span>(<span class="hljs-number">2.</span><span class="hljs-type">W</span>)    -&gt; <span class="hljs-type">Mux</span>(redirect.id_taken, <span class="hljs-string">&quot;b11&quot;</span>.<span class="hljs-type">U</span>(<span class="hljs-number">2.</span><span class="hljs-type">W</span>), <span class="hljs-string">&quot;b01&quot;</span>.<span class="hljs-type">U</span>(<span class="hljs-number">2.</span><span class="hljs-type">W</span>)),
        <span class="hljs-string">&quot;b11&quot;</span>.<span class="hljs-type">U</span>(<span class="hljs-number">2.</span><span class="hljs-type">W</span>)    -&gt; <span class="hljs-type">Mux</span>(redirect.id_taken, <span class="hljs-string">&quot;b11&quot;</span>.<span class="hljs-type">U</span>(<span class="hljs-number">2.</span><span class="hljs-type">W</span>), <span class="hljs-string">&quot;b10&quot;</span>.<span class="hljs-type">U</span>(<span class="hljs-number">2.</span><span class="hljs-type">W</span>))
    ))
    when(redirect.id_taken){        <span class="hljs-comment">//&#x53D1;&#x751F;&#x4E86;&#x5206;&#x652F;&#x8DF3;&#x8F6C;</span>
        <span class="hljs-type">BTB</span>(btb_widx).valid     := <span class="hljs-literal">true</span>.<span class="hljs-type">B</span> 
        <span class="hljs-type">BTB</span>(btb_widx).tag       := btbTag(redirect.id_pc)
        <span class="hljs-type">BTB</span>(btb_widx).target    := redirect.id_target
    }
}
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="6中断异常.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: 简单的中断异常支持">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"分支预测器","level":"5.7","depth":1,"previous":{"title":"简单的中断异常支持","level":"5.6","depth":1,"path":"ysyx/FangCore/6中断异常.md","ref":"ysyx/FangCore/6中断异常.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"ysyx/FangCore/7分支预测器.md","mtime":"2022-08-24T03:52:59.816Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-04-12T09:28:35.525Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

